package 链表和树.二叉树;

import javax.swing.tree.TreeNode;

//Java：对称二叉树
public class SymmetricTree{
    public static void main(String[] args) {
        Solution solution = new SymmetricTree().new Solution();
    }
    //leetcode submit region begin(Prohibit modification and deletion)
//    public class TreeNode {
//        int val;
//        TreeNode left;
//        TreeNode right;
//        TreeNode() {}
//        TreeNode(int val) { this.val = val; }
//        TreeNode(int val, TreeNode left, TreeNode right) {
//            this.val = val;
//            this.left = left;
//            this.right = right;
//        }
//    }
class Solution {
        //和相同的树区别在于现在是判断一个树的左右节点
    public boolean isSymmetric(TreeNode root) {
        return isSameTree(root.left, root.right);
    }
    public boolean isSameTree(TreeNode p, TreeNode q){
         if(p == null || q == null){
             return p == q;
         }

         return p.val == q.val && isSameTree(p.left, q.right) && isSameTree(p.right , q.left);
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}